package com.zhuiyun.educations.api.sysmenuback.mapper;

import com.zhuiyun.educations.api.sysmenuback.entiy.SysMenuBack;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @ClassName SysMenuBackMapper
 * @Description TODO
 * @Author MJL
 * @Date 2023/6/19 9:27
 **/
@Mapper
public interface SysMenuBackMapper {

    /**
    * @Author MJL
    * @Description todo 菜单表全查（左侧导航栏）
    * @Date 2023/6/20 18:13
    * @Return  * @param null
    */
    @Select("SELECT m.* \n" +
            "FROM sys_menu m \n" +
            "JOIN sys_role r ON FIND_IN_SET(m.id, r.menu_ids) \n" +
            "JOIN sys_user u ON u.role_id = r.id \n" +
            "WHERE u.user_login_name = #{userLoginName} and m.del_flag = 0")
    List<SysMenuBack> SysMenuList(String userLoginName);

    /**
    * @Author MJL
    * @Description todo 菜单表全查
    * @Date 2023/6/20 18:13
    * @Return  * @param null
    */
    @Select("<script>select * from sys_menu where del_flag = 0 " +
            "<when test = 'menuName != &quot;&quot; and menuName != null'>" +
            " and menu_name like concat('%',#{menuName},'%') </when> " +
            "<when test = 'menuType != &quot;&quot; and menuType != null'>" +
            "and menu_type like concat('%',#{menuType},'%') </when> " +
            " </script>")
    List<SysMenuBack> SysMenuBackList(SysMenuBack sysMenuBack);

    /**
    * @Author MJL
    * @Description todo 菜单表添加目录
    * @Date 2023/6/20 18:12
    * @Return  * @param null
    */
    @Insert("insert into sys_menu (menu_name,menu_type,menu_remark," +
            "menu_parent_id,icon,menu_select_logotype,create_time,del_flag) " +
            "values (#{menuName},#{menuType},#{menuRemark}," +
            "#{menuParentId},#{icon},#{menuSelectLogotype},#{createTime},#{delFlag})")
    int SysMenuDirectoryAdd(SysMenuBack sysMenuBack);

    /**
    * @Author MJL
    * @Description todo 菜单表添加子菜单
    * @Date 2023/6/20 19:10
    * @Return  * @param null
    */
    @Insert("insert into sys_menu (menu_name,path,menu_type," +
            "menu_remark,menu_parent_id,menu_parent_name,icon," +
            "create_time,del_flag) values (#{menuName},#{path}," +
            "#{menuType},#{menuRemark},#{menuParentId}," +
            "#{menuParentName},#{icon},#{createTime},#{delFlag})")
    int SysMenuSunAdd(SysMenuBack sysMenuBack);

    /**
    * @Author MJL
    * @Description todo 获取下拉菜单数据（父级名称）
    * @Date 2023/6/20 20:53
    * @Return  * @param null
    */
    @Select("select id,menu_name from sys_menu where menu_select_logotype = #{menuSelectLogotype}")
    List<SysMenuBack> MenuSelectList(String menuSelectLogotype);

    /**
    * @Author MJL
    * @Description todo 菜单表删除
    * @Date 2023/6/21 11:34
    * @Return  * @param null
    */
    @Update("update sys_menu set del_flag = 1,menu_select_logotype = null" +
            " where id = #{id}")
    int SysMenuUpdateDelete(Integer id);

    /**
    * @Author MJL
    * @Description todo 菜单表修改目录
    * @Date 2023/6/21 13:16
    * @Return  * @param null
    */
    @Update("update sys_menu set menu_name = #{menuName},menu_remark = #{menuRemark}," +
            "icon = #{icon},update_time = #{updateTime} where id = #{id}")
    int SysMenuDirectoryUpdate(SysMenuBack sysMenuBack);

    /**
    * @Author MJL
    * @Description todo 菜单表修改子菜单
    * @Date 2023/6/21 14:43
    * @Return  * @param null
    */
    @Update("update sys_menu set menu_name = #{menuName},path = #{path}," +
            "menu_remark = #{menuRemark},menu_parent_id = #{menuParentId}," +
            "menu_parent_name = #{menuParentName},icon = #{icon}," +
            "update_time = #{updateTime} where id = #{id}")
    int SysMenuSunUpdate(SysMenuBack sysMenuBack);
}
